package com.spring.shops.admin.controller.shop;
import com.spring.shops.model.dto.PickAddrDTO;
import com.spring.shops.model.entity.TzPickAddr;
import com.spring.shops.model.result.IPageIndexImg;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.IndexImg;
import com.spring.shops.service.PickAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop/pickAddr")
public class PickAddrController {
    @Autowired
    private PickAddrService pickAddrService;
    /**
     * 新增自提点
     * @param tzPickAddr
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody TzPickAddr tzPickAddr){
        boolean flag= pickAddrService.save(tzPickAddr);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }

    /**
     * 分页查询
     * @param dto
     */
    @GetMapping("/page")
    public ServerResponseEntityVoid<IPageIndexImg<TzPickAddr>> page(PickAddrDTO dto){
        return pickAddrService.page(dto);
    }

    /**
     * 批量删除数据
     * @param integers
     * @return
     */
    @DeleteMapping
    public ServerResponseEntityVoid deleteByIds(@RequestBody List<Integer> integers){
        boolean flag=pickAddrService.deleteByIds(integers);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }

    /**
     * 根据id获取数据
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public ServerResponseEntityVoid<TzPickAddr> getById(@PathVariable Integer id){
         return pickAddrService.getById(id);
    }
    /**
     * 更新数据
     * @param tzPickAddr
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid update(@RequestBody TzPickAddr tzPickAddr){
        boolean flag=pickAddrService.update(tzPickAddr);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }
}
